const express = require('express');
const router = express.Router()
const articlesCtrl = require('../controller/articles')
const articleValidator = require('../validator/articles');
const auth = require('../middleware/auth')

// 从关注的用户那里获取最新的文章
router.get('/feed', auth, articlesCtrl.getFollowArticles)
// 获取文章列表
router.get('/', articlesCtrl.getArticles)
// 创建文章
router.post('/', auth, articleValidator.createArticle, articlesCtrl.createArticle)
// 获取文章
router.get('/:articleId', articleValidator.getArticle, articlesCtrl.getArticle)
// 修改文章
router.put('/:articleId', auth, articleValidator.updateArticle, articlesCtrl.updateArticle)
// 删除文章
router.delete('/:articleId', auth, articleValidator.deleteArticle, articlesCtrl.deleteArticle)

// 获取文章评论列表
router.get('/:articleId/comments', articlesCtrl.getComments)
// 发表评论
router.post('/:articleId/comments', auth, articlesCtrl.sendComment)
// 删除评论
router.delete('/:articleId/comments/:id', auth, articlesCtrl.deleteComment)

// 收藏文章
router.post('/:articleId/favorite', auth, articlesCtrl.favoriteComment)
// 取消收藏
router.delete('/:articleId/favorite', auth, articlesCtrl.cancelFavoriteComment)

module.exports = router